<template>
<div class="banner-list">
  <div style="display:flex;align-items: center;margin:0 0 10px;">
    <div class="">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="标题">
          <el-input size="small" v-model="formInline.title" placeholder="标题"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="">
      <el-button size="small" type="primary" @click="add">新建轮播图</el-button>
    </div>
  </div>
  <el-table ref="multipleTable" v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row empty-text="暂无数据">
    <el-table-column align="center" label="序号" width="150">
      <template slot-scope="scope">
        {{ scope.row.name }}
      </template>
    </el-table-column>
    <el-table-column label="标题">
      <template slot-scope="scope">
        {{ scope.row.title }}
      </template>
    </el-table-column>
    </el-table-column>
    <el-table-column label="链接地址" width="200" align="center">
      <template slot-scope="scope">
        {{ scope.row.link }}
      </template>
    </el-table-column>
    <el-table-column label="缩略图" width="180" align="center">
      <template slot-scope="scope">
        <img :src="scope.row.imgUrl" alt="" style="width:120px;height:80px;">
      </template>
    </el-table-column>
    <el-table-column fixed="right" align="center" label="操作" width="100">
      <template slot-scope="scope">
        <el-button @click="edit(scope.row)" type="text">编辑</el-button>
        <el-button type="text" style="color:#ff0000;">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div style="margin:10px 0 0 0;text-align:right;">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 30, 50, 100]"
      :page-size="1"
      layout="total, sizes, prev, pager, next, jumper"
      :total="10">
    </el-pagination>
  </div>
</div>
</template>

<script>
import {
  getList
} from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [{
          name: '1',
          title: '13322221111',
          link: 'https://www.baidu.com',
          imgUrl: 'https://img-cdn-aliyun.dcloud.net.cn/stream/plugin_screens/7908a740-5488-11e9-b307-d310fdb71328_0.png?v=1621141024',
        },
        {
          name: '2',
          title: '13322221111',
          link: 'https://www.taobao.com',
          imgUrl: 'https://img-cdn-aliyun.dcloud.net.cn/stream/plugin_screens/7908a740-5488-11e9-b307-d310fdb71328_0.png?v=1621141024',
        },
      ],
      listLoading: true,
      currentPage: 1,
      formInline: {
        title: '',
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    onSubmit() {

    },
    add() {
      this.$router.push({
        path: '/banner/add'
      })
    },
    edit(row) {
      console.log(row)
      this.$router.push({
        path: '/banner/edit'
      })
    },
    fetchData() {
      this.listLoading = true
      getList().then(response => {
        // this.list = response.data.items
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
}
</script>

<style lang="scss" scoped>
   .banner-list{
     padding: 20px;
     .el-form-item{
       margin-bottom: 0;
     }
   }
</style>
